package com.chebaohui.iqs.service.impl.deal.taiping.ev;
import com.alibaba.fastjson.JSONObject;
import com.chebaohui.iqs.config.CompanyValue;
import com.chebaohui.iqs.service.impl.deal.taiping.DirectTp;
import com.chebaohui.iqs.service.impl.deal.taiping.PublicNew;
import com.chebaohui.iqs.service.impl.deal.taiping.RequestHead;
import com.chebaohui.iqs.service.impl.deal.taiping.ResTaiPing;
import com.chebaohui.iqs.service.impl.deal.util.StringUtil;

/**
 * E04-保存订单车险信息
 * 
 * @author xielonghai
 * @version 2016-07-07
 */
public class E04Request {

	/**
	 * 保存订单车险-接口方法
	 * 
	 * @param session
	 *            会话ID--初始为空,后续调用为上次request返回
	 * @param param
	 *            请求参数json
	 * @return
	 */
	public static ResTaiPing requestE04(String session, JSONObject param) {
		// 接口描述
		String value = CompanyValue.TAIPING + ":辅助接口-保存订单车险";

		String[] key = { "order" };

		return DirectTp.request(value, PublicNew.REQUEST_URL + "/saveOrderVehicle", getRequest(session, param), key);
	}

	/**
	 * 获取--E04-保存订单车险信息------请求参数
	 * 
	 * @param session
	 *            会话ID--初始为空,后续调用为上次request返回
	 * @param param
	 *            请求参数json
	 * @return
	 */
	private static String getRequest(String session, JSONObject param) {
		JSONObject head = RequestHead.getHead(session);
		String request = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
		request = request + "\n" + "<request>";
		request = request + "\n" + "<head>";

		request = request + "\n\t" + "<msgId>" + head.getString("msgId") + "</msgId>";
		request = request + "\n\t" + "<timeStamp>" + head.getString("timeStamp") + "</timeStamp>";
		request = request + "\n\t" + "<session>" + head.getString("session") + "</session>";
		request = request + "\n\t" + "<userCode>" + head.getString("userCode") + "</userCode>";
		request = request + "\n\t" + "<clientName>" + head.getString("clientName") + "</clientName>";

		request = request + "\n" + "</head>";
		request = request + "\n" + "<body>";

		String orderNo = param.getString("orderNo");
		if (null == orderNo)
			orderNo = "";
		request = request + "\n\t" + "<order>";
		request = request + "\n\t\t" + "<orderNo>" + orderNo + "</orderNo>";// orderNo
		request = request + "\n\t" + "</order>";

		request = request + "\n\t" + "<sales>";
		if (!StringUtil.isNulls(param.getString("cityCode"))) {// 城市代码
			request = request + "\n\t\t" + "<cityCode>" + param.getString("cityCode") + "</cityCode>";// 城市代码
		}
		request = request + "\n\t\t" + "<groupNo>" + PublicNew.groupNo + "</groupNo>";// 团队号
		request = request + "\n\t\t" + "<solutionCode>" + PublicNew.solutionCode + "</solutionCode>";// 子协议代码
		request = request + "\n\t\t" + "<salesmanCode>" + PublicNew.salesmanCode + "</salesmanCode>";// 业务员代码
		request = request + "\n\t" + "</sales>";

		request = request + "\n\t" + "<carOwner>";
		request = request + "\n\t\t" + "<name>" + param.getString("name") + "</name>";// 车主名称
		request = request + "\n\t" + "</carOwner>";

		request = request + "\n\t" + "<vehicle>";
		request = request + "\n\t\t" + "<licenseNo>" + param.getString("licenseNo") + "</licenseNo>";// 车牌号-若是新车，传送“暂未上牌”
		request = request + "\n\t\t" + "<frameNo>" + param.getString("frameNo") + "</frameNo>";// 车架号--只能大写字母和数字
		request = request + "\n\t\t" + "<engineNo>" + param.getString("engineNo") + "</engineNo>";// 发动机号
		request = request + "\n\t\t" + "<modelCode>" + param.getString("modelCode") + "</modelCode>";// 精友车型编码
		request = request + "\n\t\t" + "<chgOwnerFlag>" + param.getString("chgOwnerFlag") + "</chgOwnerFlag>";// 是否过户车-00、非过户车，01投保过户
		request = request + "\n\t\t" + "<transferDate>" + param.getString("transferDate") + "</transferDate>";// 过户日期-若是过户车，需传值；
		request = request + "\n\t\t" + "<singeinDate>" + param.getString("SingeinDate") + "</singeinDate>";// 登记日期
		request = request + "\n\t" + "</vehicle>";

		request = request + "\n" + "</body>";
		request = request + "\n" + "</request>";
		return request;
	}
}
